<?php
/**
 * BQue Description
 * @package core
 * @name Controller
 * @filesource Controller.php
 * @author Meta Sanjaya
 */

class Controller extends System
{
    private $variable;

    /**
     * @access public
     * @method __construct
     * @param void
     * @return void
     */
    public function __construct()
    {
        $this->variable = array();
        getInstance('config')->retrieve(getInstance('uri')->getApp());
    }

    /**
     * @access protected
     * @method addVar
     * @param String $name
     * @param Mixed $value
     * @return void
     */
    public function addVar($name, $value)
    {
        $this->variable[$name] = $value;
    }

    public function addVars($array=array())
    {
        foreach($array as $key => $value) {
            $this->addVar($key, $value);
        }
    }

    /**
     * @access protected
     * @method renderView
     * @param Boolean $return
     * @return Mixed
     */
    public function renderView($view, $app='',$return=false)
    {
        if($return) {
            $return = Page::returnView($this->variable, $view, $app);
        } else {
            Page::display($this->variable, $view, $app);
        }

        $this->variable = array();
        return $return;
    }

    /**
     * @access protected
     * @method loadModel
     * @param String $model
     * @return void
     */
    public function getModel($app='')
    {
        try {
            $app = (is_null($app)||empty($app)?getInstance('uri')->getApp():$app);
            $model = 'model_' . $app;
            include_once __APP__ . $app . DIRECTORY_SEPARATOR . $model . '.php';
            return(new $model);
        } catch(Exception $e) {
            trigger_error($e->getMessage());
        }
    }

    public function getLanguage($app='',$lang_id='en')
    {
        try {
            $app = (is_null($app)||empty($app)?getInstance('uri')->getApp():$app);
            return(Language::load($app, $lang_id));
        } catch(Exception $e) {
            trigger_error($e->getMessage());
        }
    }

    public function hasAccessControl()
    {
        return User::hasAccessControl(getInstance('uri')->getApp(), getInstance('uri')->getAct());
    }

    public function __default() { }
}
?>
